package com.gomtel.smartdevice.ui.adapter;

import android.content.Context;

import com.clj.fastble.data.BleDevice;
import com.gomtel.smartdevice.base.BasicAdapter;
import com.gomtel.smartdevice.base.BasicHolder;
import com.gomtel.smartdevice.bean.PulseConditionBeanPlus;
import com.gomtel.smartdevice.moudle.db.entity.AtrialFibrillationInfo;
import com.gomtel.smartdevice.moudle.db.entity.BdDataInfo;
import com.gomtel.smartdevice.moudle.db.entity.EcgDataInfo;
import com.gomtel.smartdevice.moudle.db.entity.PulseConditionBean;
import com.gomtel.smartdevice.ui.holder.AtrialFibrillationHolder;
import com.gomtel.smartdevice.ui.holder.BdDataHolder;
import com.gomtel.smartdevice.ui.holder.DeviceContentHolder;
import com.gomtel.smartdevice.ui.holder.EcgDataHolder;
import com.gomtel.smartdevice.ui.holder.PulseConditionHolder;
import com.gomtel.smartdevice.ui.holder.PulseConditionHolderLJF;

import java.security.InvalidParameterException;
import java.util.ArrayList;

/**
 * Created by Administrator on 2018/5/26 0026.
 */

public class AdapterStandardGeneral extends BasicAdapter<Object> {

    private Context context;
    private ArrayList<Object> mList;
    public static final int TYPE_EXECPTION = 0;
    public static final int TYPE_ECG = 1;  //心电
    public static final int TYPE_BD = 2;  //血压
    public static final int TYPE_BLUE_TOOTH = 3;  //设备信息
    public static final int TYPE_PULSE_CONDITON = 4;  //脉诊
    public static final int TYPE_AF = 5;  //房颤
    public static final int TYPE_PULSE_CONDITON_LJF = 6;  //脉诊
    public final int TypeCount = 7;

    public AdapterStandardGeneral(ArrayList<Object> list, Context context) {
        super(list);
        this.mList = list;
        this.context = context;
    }

    @Override
    protected BasicHolder<Object> getHolder(int position) {
        switch (getItemViewType(position)) {
            case TYPE_ECG:
                return new EcgDataHolder(context);
            case TYPE_BD:
                return new BdDataHolder(context);
            case TYPE_BLUE_TOOTH:
                return new DeviceContentHolder(context);
            case TYPE_PULSE_CONDITON_LJF:
                return new PulseConditionHolderLJF(context);
            case TYPE_AF:
                return new AtrialFibrillationHolder(context);
            case TYPE_PULSE_CONDITON:
                return new PulseConditionHolder(context);
            default:
                throw new InvalidParameterException();
        }

    }

    @Override
    public int getItemViewType(int position) {
        if (getItem(position) instanceof EcgDataInfo) {
            return TYPE_ECG;
        } else if (getItem(position) instanceof BdDataInfo) {
            return TYPE_BD;
        } else if (getItem(position) instanceof BleDevice) {
            return TYPE_BLUE_TOOTH;
        } else if (getItem(position) instanceof PulseConditionBean) {
            return TYPE_PULSE_CONDITON_LJF;
        } else if (getItem(position) instanceof AtrialFibrillationInfo) {
            return TYPE_AF;
        } else if (getItem(position) instanceof PulseConditionBeanPlus) {
            return TYPE_PULSE_CONDITON;
        }
        return TYPE_EXECPTION;
    }

    @Override
    public int getViewTypeCount() {
        return TypeCount;
    }
}

